<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
       <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f"%>
<%@page import="java.util.List"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" href="${pageContext.request.contextPath}/layui-v2.6.13/layui/css/layui.css">
		<script type="text/javascript" src="${pageContext.request.contextPath}/layui-v2.6.13/layui/layui.js"></script>
		<script type="text/javascript" type="text/css"  src="${pageContext.request.contextPath}/js/jquery.min-2.1.1.js"></script>
	</head>
	<body>
		<div style="padding: 20px;">
			<div >
				
				<button class="layui-btn" onclick="add()">添加</button>
			</div>
			
			<div>
				<table class="layui-table">
					
					<thead>
						<tr>
							<th>
								<input type="checkbox">
							</th>
							
							<th>专业ID</th>
							<th>专业名称</th>
							<th>所属院校</th>
							<th>操作</th>
							
						</tr> 
					</thead>
					<tbody>
					<c:forEach items="${list}" var="obj">
						<tr>
							<td><input type="checkbox"></td>
							<th>${obj.majorId}</th>
							<th>${obj.cName}</th>
							<th>${obj.collegeId}</th>
							<td>
									<button class="layui-btn layui-btn-sm" onclick="insert(${obj.id},'${obj.cName}');">更新</button>
							</td>
							</tr>
							</c:forEach>
						</tbody>
					</table>
				</div>
				<div id="limitPage" align="center">
				<button class="layui-btn layui-btn-sm layui-btn-primary layui-border-green" onclick="queryByPageNo(1,${totalPage});">首页</button>
				<button class="layui-btn layui-btn-sm" onclick="queryByPageNo(${pageNo-1},${totalPage});">上一页</button>
				<span class="layui-font-16" >${pageNo}/ ${totalPage}页</span>
				<button class="layui-btn layui-btn-sm" onclick="queryByPageNo(${pageNo+1},${totalPage});">下一页</button>
				<button class="layui-btn layui-btn-sm layui-btn-primary layui-border-green" onclick="queryByPageNo(${totalPage},${totalPage});">尾页</button>
			</div>
		</div>
	</body>
	<script >
	function queryByPageNo(pageNo,totalPage){
		if(pageNo<1) pageNo=1;
		if(totalPage<pageNo) pageNo =totalPage;
		window.location.href="major?m=majorSelect&pageNo="+pageNo;
		
		}
	
	</script>
		<script>
			function insert(id,name){
				layui.use('layer',function(){
					layer.open({
					  type: 2, 
					  title: '更新',
					  content: 'major?m=majorUpdatePage&id='+id+'&sName='+name,
					  area:['1000px','500px']
					});
				})
			}
			function add(){
				layui.use('layer',function(){
					layer.open({
						type:2,
						title:'增加',
						content:'major?m=majorInsertPage',
						area:['1000px','500px']
					});
				})
			}
		</script>
		
		<script>
	//注册layui弹层组件
	layui.use(['layer','form'], function(){
		var layer = layui.layer;
		var form = layui.form;
		
		//二级联动：查询学院对应的专业列表
		//select标签绑定触发事件
		form.on('select(filter)', function(data){
			console.info(data.elem);//得到select原始DOM对象
			console.info(data.value);//得到该选中的值
			
			var params = "m=listOfAcademyId&collegeId=" + data.value;
			
			$.ajax({
				url:"m",
				data:params,
				type:"POST",
				success: function(obj){
					//json字符串转数组
					var arr = JSON.parse(obj);
					
					$("#major").empty();
					
					//添加子元素
					$.each(arr, function(index, item){
						$("#major").append("<option value='"+item.majorId+"'>"+item.sName+"</option>");
					});
					//重新渲染select下拉框
					form.render('select');
				}
			});
		});
	});
</script>
	</html>